package com.yidu.BusinessParament.controller;


import com.yidu.BusinessParament.entity.Bond;
import com.yidu.BusinessParament.service.BondService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 周楠櫻木
 * @version 1.0
 * @date 2022/12/6
 */
@RestController
public class BondController {
    @Resource
    BondService bondService;

    /**
     *查询所有bond和分页
     * @param bond Bond类
     * @param page 当前页
     * @param limit 每页显示数
     * @return
     */
    @RequestMapping("/selectBond")
    public Map selectBond(Bond bond, int page, int limit){
        List<Bond> bondList = bondService.selectBond(bond,page,limit);
        int getSumRow = bondService.getSumRow(bond);
        Map  map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",getSumRow);
        map.put("data",bondList);

        return map;
    }

    /**
     * 债券新增
     * @param bond
     * @return
     */
    @RequestMapping("/insertBond")
    public int insertBond(Bond bond) {
        int i = bondService.insertBond(bond);
        return i;
    }

    /**
     * 债券删除
     * @param bondId
     * @return
     */
    @RequestMapping("/deleteBond")
    public int  deleteBond(String bondId) {
        System.out.println("进来了");
        int a = bondService.deleteBond(bondId);
        return a;

    }

    /**
     * 债券修改
     * @param bond
     * @return
     */
    @RequestMapping("/updateBond")
    public int updateBond(Bond bond) {
        System.out.println("进来了");
        System.out.println(bond);

        return bondService.updateBond(bond);
    }

}
